package com.ag.zrt.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ag.bean.TbCurrentEvent;
import com.ag.zrt.dao.TbCurrentEventDAO;
import com.ag.zrt.service.ICurrentEventService;

@Service("ZRTCurrentEventService")
public class CurrentEventServiceImpl implements ICurrentEventService {

	@Resource(name = "ZRTTbCurrentEventDAO")
	private TbCurrentEventDAO curEventDAO;

	public void setCurEventDAO(TbCurrentEventDAO curEventDAO) {
		this.curEventDAO = curEventDAO;
	}

	@Override
	public TbCurrentEvent findById(String id) {
		// TODO Auto-generated method stub
		return curEventDAO.findById(id);
	}

	@Override
	public int updateCurrentStepNum(String eventId, String currentStepId) {
		// TODO Auto-generated method stub

		try {
			System.out.println("**********updateCurrentStepNum*****eventId="
					+ eventId+"********************currentStepId**************"+currentStepId);
			TbCurrentEvent ce = curEventDAO.findById(eventId);

			//Long curNum = ce.getCeNumber();
			int curNum = ce.getCeNumber();

			curNum += 1;

			ce.setCeNumber(curNum);
			
			ce.setCurStepId(currentStepId);

			curEventDAO.attachDirty(ce);

			TbCurrentEvent ce_new = curEventDAO.findById(eventId);

			System.out.println("*************ce_new**********************"
					+ ce_new.getCeNumber());
			
			//updateCurrentStepId(eventId,currentStepId);
			
			return ce_new.getCeNumber().intValue();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
		
	}

	@Override
	public void updateCurrentStepId(String eventId, String currentStepId) {
		// TODO Auto-generated method stub
		System.out.println("**********updateCurrentStepId*****eventId="
				+ eventId + "**********currentStepId=" + currentStepId);
		try {
			TbCurrentEvent ce = curEventDAO.findById(eventId);
			System.out
					.println(ce.getEId()
							+ "*-/-/-*/-*/-*/-*/-*/-*/-*/-*/-*/-*/-*/-*/-/-/-/-/-*/-*-*/-*/-*-*/-");
			if (ce.getCurStepId() != currentStepId) {
				ce.setCurStepId(currentStepId);
				curEventDAO.attachDirty(ce);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
